﻿using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.UI.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace classTest
{
    /// <summary>
    /// BufferEffectLayerAttributeTableWindow.xaml 的交互逻辑
    /// </summary>
    public partial class BufferEffectLayerAttributeTableWindow : Window
    {
        private FeatureQueryResult pQueryResult;
        private MapView mapView;
        public BufferEffectLayerAttributeTableWindow(FeatureQueryResult pQueryResult1, MapView mapView1)
        {
            InitializeComponent();
            pQueryResult = pQueryResult1;
            mapView = mapView1;
            Initialize();
        }
        private void Initialize()
        {
            List<Feature> listFeatures = pQueryResult.ToList();
            countLayer.Content = $"共影响{pQueryResult.Count()}个图层要素";
            for(int i=0;i< listFeatures.Count(); i++)
            {
                ComboBoxItem cbi = new ComboBoxItem();
                cbi.Content = $"第{i+1}个图层要素";
                cbi.DataContext = listFeatures[i];
                layerComboBox.Items.Add(cbi);
            }
            layerComboBox.SelectedIndex = 0;
        }

        private async void LayerComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (layerComboBox.SelectedIndex!=1){
                Feature f = (layerComboBox.SelectedItem as ComboBoxItem).DataContext as Feature;
                dataGrid.ItemsSource = f.Attributes;
                dataGrid.AutoGenerateColumns = true;
                await mapView.SetViewpointGeometryAsync(f.Geometry.Extent);
            }

        }
    }
}
